import { Control } from 'react-keeper';
import { Toast } from 'saltui';
const Actions = require('./actions');
const DB = require('app/db.js');
import { Storage } from 'clientConfig/util/StoreData'
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
    },
    //获取打分列表
    onFetch: function (params, cb) {
        let t = this;
        if (params.origin == "new") {
            if (JSON.stringify(t.data) != "{}") {
                t.data = {};
            }
        }else if(params.origin == "original"){
            if (JSON.stringify(t.data) != "{}") {
                cb&&cb();
                t.updateComponent();
            }           
        }    
        DB.Teacher.get_scoreCategory_list({
            schoolId: Storage.get('user.schoolId'),
        })
            .then((content) => {
                if (content && content.code == 1) {
                    let schoolId = content.check.schoolId;
                    var obj = {};
                    const popcontent = [];
                    let data = content.data;
                    if (data && data.timeList.length > 0) {
                        for (let item of data.timeList) {
                            item.isslect = false;
                        }
                    }
                    if (data && data.typeList.length > 0) {
                        for (let item of data.typeList) {
                            item.isslect = false;
                        }
                    }
                    for (let key in data) {
                        if (key == "timeList") {
                            obj.title = "时间批次";
                        }
                        if (key == "typeList") {
                            obj.title = "检查类别"
                        }
                        obj.content = data[key];
                        popcontent.push(obj);
                        obj = {};
                    }
                    t.data.popcontent = popcontent;
                    t.updateComponent();
                }else{
                    Toast.show({
                        type: 'error',
                        content: '系统异常'
                    });
                }

            })
            .catch(function (error) {
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            });
    },
    //获取位置列表数据
    onGetSanitationLocationList: function (params, cb) {
        let t = this;
        DB.Teacher.get_sanitationLocation_list({
            schoolId: Storage.get('user.schoolId'),
            classifyId: params.classifyId,//‘’全部
            timeId: params.timeId,
            typeId: params.typeId
        })
            .then((content) => {
                if (content.code == 1) {
                    if (content && content.data) {
                        content = content.data.list;
                    }
                    t.data.listdata = content;
                    t.updateComponent();
                }else{
                    Toast.show({
                        type: 'error',
                        content: '系统异常'
                    });
                }
            })
            .catch(function (error) {
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            });
    },
    //获取卫生分类
    onGetSanitationClassifyList: function (params, cb) {
        let t = this;
        DB.Teacher.get_sanitationClassify_list({
            schoolId: Storage.get('user.schoolId')
        })
            .then((content) => {
                if (content.code == 1) {
                    if (content && content.data) {
                        content = content.data.list;
                    }
                    if (content && content.length > 0) {
                        for (let item of content) {
                            item.text = item.name;
                        }
                    }
                    t.data.sanitationClassify = content;
                    t.updateComponent();
                }else{
                    Toast.show({
                        type: 'error',
                        content: '系统异常'
                    });
                }
            })
            .catch(function (error) {
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            });
    },
    updateComponent: function () {
        this.trigger(this.data);
    }
});
